﻿Type.registerNamespace('Itvirtuoso');

Itvirtuoso.ScrollBehavior = function(element) {
    Itvirtuoso.ScrollBehavior.initializeBase(this, [element]);
    this._scrollId = null;
}

Itvirtuoso.ScrollBehavior.prototype = {
    initialize : function() {
        Itvirtuoso.ScrollBehavior.callBaseMethod(this, 'initialize');
        $addHandlers(this.get_element(), 
            { 'scroll' : this._onScroll },
            this);
    
        var top = document.getElementById(this._scrollId).value;
        if(top != '') {
            var undefined;
            var panel = this.get_element();
            if(panel.scrollTop !== undefined) {
                panel.scrollTop = top;
            } else if(panel.scrollY !== undefined) {
                panel.scrollY = top;
            }
        }
    },
    
    dispose: function() {
        $clearHandlers(this.get_element());
        Itvirtuoso.ScrollBehavior.callBaseMethod(this, 'dispose');
    },
    
    _onScroll : function(e) {
        document.getElementById(this._scrollId).value = e.target.scrollTop || e.target.scrollY;
    },
    
    get_scrollId : function() {
        return this._scrollId;
    },
    
    set_scrollId : function(value) {
        if(this._scrollId !== value) {
            this._scrollId = value;
            this.raisePropertyChanged('scrollId');
        }
    }
}

Itvirtuoso.ScrollBehavior.registerClass('Itvirtuoso.ScrollBehavior', Sys.UI.Behavior);
if(typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
